package com.adopapa.nezhacloud.authc.domain;

import java.time.Instant;
import java.util.HashMap;
import java.util.Map;

import org.springframework.util.ObjectUtils;

import com.adopapa.nezhacloud.ddd.codegen.CodeGen;
import com.adopapa.nezhacloud.ddd.domain.BaseUuidEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;

@Entity
@Table(name = "AUTHC_USER")
public class UserInfo extends BaseUuidEntity {

	private static final long serialVersionUID = 6027412795834172463L;

	@CodeGen(query = "=", form = true, unique = true, required = true, label = "用户名称")
	@Column(name = "LOGIN_NAME")
	private String loginName;
	@CodeGen(form = true, required = true, label = "用户密码")
	@Column(name = "LOGIN_PWD")
	private String loginPwd;
	@CodeGen(query = "%", form = true, required = true, label = "姓名")
	@Column(name = "USER_NAME")
	private String userName;
	@CodeGen(form = true, label = "备注")
	@Lob
	@Column(name = "REMARK")
	private String remark;
	@CodeGen(query = ">=", time = true, label = "开始时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
	@Column(name = "CREATE_TIME")
	private Instant createTime;
	@Transient
	@CodeGen(query = "<", time = true, label = "结束时间")
	private Instant createTime2;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
	@Column(name = "UPDATE_TIME")
	private Instant updateTime;
	@JsonIgnore
	@ManyToOne
	@JoinColumn(name = "DEPARTMENT_ID")
	private DepartmentInfo departmentInfo;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getLoginPwd() {
		return loginPwd;
	}

	public void setLoginPwd(String loginPwd) {
		this.loginPwd = loginPwd;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Instant getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Instant createTime) {
		this.createTime = createTime;
	}

	public Instant getCreateTime2() {
		return createTime2;
	}

	public void setCreateTime2(Instant createTime2) {
		this.createTime2 = createTime2;
	}

	public Instant getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Instant updateTime) {
		this.updateTime = updateTime;
	}

	public DepartmentInfo getDepartmentInfo() {
		return departmentInfo;
	}

	public void setDepartmentInfo(DepartmentInfo departmentInfo) {
		this.departmentInfo = departmentInfo;
	}

	public Map<String, String> getDepartment() {
		if (!ObjectUtils.isEmpty(this.departmentInfo)) {
			Map<String, String> department = new HashMap<String, String>();
			department.put("deptId", this.departmentInfo.getId());
			department.put("deptName", this.departmentInfo.getId());
			return department;
		}
		return null;
	}

}
